package com.wetsion.securityoauthdemo.rmsclient.filter;

import org.springframework.core.annotation.Order;
import org.springframework.util.StringUtils;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author weixin
 * @version 1.0
 * @CLassName RmsGlobalFilter
 * @date 2019/3/13 4:36 PM
 */
@WebFilter(urlPatterns = "/*", filterName = "rmsGlobalFilter")
@Order(99)
public class RmsGlobalFilter implements Filter {
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("global");
        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
        String currentUrl = httpServletRequest.getRequestURL().toString();
        if (!StringUtils.isEmpty(httpServletRequest.getQueryString())) {
            currentUrl += httpServletRequest.getQueryString();
        }
        request.setAttribute("currentUri", currentUrl);
        chain.doFilter(request, response);
    }
}
